package com.wjt.homestayms.common;

import lombok.Data;

import java.util.Map;


public class Result<T> {
    private boolean status;
    private Integer code;
    private String msg;
    private T result;

    static public Result ok(Object data) {
        Result result = new Result();
        result.setStatus(true);
        result.setCode(200);
        result.setResult(data);

        return result;
    }

    static public Result fail(String msg) {

        Result result = new Result();
        result.setResult(false);
        result.setCode(500);
        result.setMsg(msg);

        return result;
    }

    static public Map<String, Object> queryResult(Map<String, Object> map, PageResult resultPage){
        if (resultPage != null) {
            map.put("code", 200);
            map.put("status", true);
            map.put("result", resultPage);
        } else {
            map.put("code", 500);
            map.put("status", false);
            map.put("result", null);
        }
        return map;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }
}
